﻿using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using XEvolve.Core.Runtime;

namespace XEvolve.Core.PluginProviders
{
    public class PluginList : IEnumerable<Plugin>
    {
        private readonly IEnumerable<Plugin> plugins;

        public PluginList(params Type[] pluginTypes)
        {
            plugins = pluginTypes.Where(type => !type.IsAbstract && type.IsSubclassOf(typeof(Plugin))).Select(type => (Plugin)type.GetConstructor(new Type[0]).Invoke(new object[0]));
        }

        public IEnumerator<Plugin> GetEnumerator()
        {
            return plugins.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }
}
